package com.example.chcrm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.chcrm.entity.common.ResponseMsg;
import com.example.chcrm.entity.employee.SupplierPort;
import com.example.chcrm.entity.employee.WarehouseManagement;
import com.example.chcrm.mapper.RoleModelsMapper;
import com.example.chcrm.mapper.SupplierPortMapper;
import com.example.chcrm.mapper.WarehouseManagementMapper;
import com.example.chcrm.service.RoleModelsService;
import com.example.chcrm.service.SupplierPortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author 邹
 * @Date 2025/4/18 23:07
 * @Version 1.0
 */
@Service
public class SupplierPortServiceImpl <T> implements SupplierPortService<T> {
    @Autowired
    private SupplierPortMapper supplierPortMapper;
    @Autowired
    private WarehouseManagementMapper warehouseManagementMapper;
    @Override
    public ResponseMsg<Object> publicSelectPort() {
        ResponseMsg<Object> msg = new ResponseMsg<>();
        //查询港口
        QueryWrapper<SupplierPort> query = new QueryWrapper<>();
        query.select("id,port_name as supplier_name");
        query.eq("status",1);
        query.eq("is_deleted",0);
        query.orderByDesc("port_name");
        List<Map<String,Object>> portList = supplierPortMapper.selectMaps(query);
        //查询库房
        QueryWrapper<WarehouseManagement> query1 = new QueryWrapper<>();
        query1.select("id,warehouse_name as supplier_name");
        query1.eq("status",1);
        query1.eq("is_deleted",0);
        query1.orderByDesc("warehouse_name");
        List<Map<String,Object>> warehoseList = warehouseManagementMapper.selectMaps(query1);
        //合并集合
        List<Map<String,Object>> combinedList = Stream.concat(portList.stream(), warehoseList.stream())
                .collect(Collectors.toList());
        msg.success("查询成功");
        msg.setData(combinedList);
        return msg;
    }
}
